package com.hh.erp.config;

import com.hh.erp.entity.SysConfig;
import com.hh.erp.service.SysConfigService;
import com.hh.erp.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * 系统启动后 执行
 * a
 */
@Configuration
public class StartConfig {

    @Autowired
    private SysConfigService sysConfigService;

    private static List<SysConfig> configList = new ArrayList<>();

    public static SysConfig getConfig(String configKey) {
        Map<String,SysConfig> map = configList.stream().collect(Collectors.toMap(p->p.getConfigKey(),p->p));
        return map.get(configKey);
     }
    @PostConstruct
    public void init() {
        if(configList == null || configList.size() == 0)
            configList = sysConfigService.getConfigList();
        System.out.println("用户配置载入完成！");
    }


}
